<?php

import("data.db.DbAbstractTable");
import("data.db.DbFactory");

/*
DROP TABLE IF EXISTS `catalogue`.`pd_product_attr`;
CREATE TABLE  `catalogue`.`pd_product_attr` (
  `proda_id` varchar(45) NOT NULL,
  `proda_id_prod` varchar(45) NOT NULL,
  `proda_value` varchar(255) NOT NULL,
  `proda_id_unita` varchar(45) NOT NULL,
  `proda_locale` varchar(6) NOT NULL default 'en_US',
  PRIMARY KEY  (`proda_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Property of product';
*/

class DbProductProperty extends DbAbstractTable {
	
	var $className = "data.logic.property.ProductProperty";
	const CLASS_NAME =  "data.logic.property.ProductProperty";
	
	//
	// SQL Table description section
	//
	const TB_TABLENAME	= "pd_product_attr";
	const TB_I			= 'proda';
	
	const TB_VALUE		= 'proda_value';
	const TB_LOCALE		= 'proda_locale';
	
	function _get_TABLENAME() {return self::TB_TABLENAME;}
	function _get_ID() {return self::TB_I."_id";}
	function _get_SUFFIX() {return self::TB_I;}
	//
	//
	
	function forwardForeignCollection() {
		return array("UnitProperty"=>"data.logic.property.UnitProperty",
			"Product"=>"data.logic.product.Product");
	}
	
	// properties
	var $value;
	var $locale;
	
	public function __construct($noinit=false) {
		parent::__construct($noinit);
	}
	
	function getDisplayValue() {
		return $this->value;
	}
	
	function getValue() {
		return $this->value;
	}
	function setValue($value) {
		$this->value = $value;
	}
	
	function getLocale() {
		return $this->locale;
	}
	function setLocale($locale) {
		$this->locale = $locale;
	}
	
	function setUnitProperty(&$unitProperty) {
		$this->forwardForeigns["UnitProperty"]->setForeign($unitProperty);
	}
	
	function getUnitProperty() {
		return $this->forwardForeigns["UnitProperty"]->getForeign();
	}
	
	function setProduct(&$product) {
		$this->forwardForeigns["Product"]->setForeign($product);
	}
	
	function getProduct() {
		return $this->forwardForeigns["Product"]->getForeign();
	}
	
	function getUnitPropertyId() {
		return $this->getForeignId('data.logic.property.UnitProperty');
	}
	
	// restore
	function fillEntity($arrResult) {
		parent::fillEntity($arrResult);
		$this->setValue($arrResult[self::TB_VALUE]);
		$this->setLocale($arrResult[self::TB_LOCALE]);
	}
	
	//store
	function fillFields() {
		parent::fillFields();
		$this->fildsForStore[self::TB_VALUE] = "'".$this->getValue()."'";
		$this->fildsForStore[self::TB_LOCALE] = "'".$this->getLocale()."'";
	}
	
	// static find

	// same for all classes
	public static function findAll() {return parent::findAll(self::CLASS_NAME);}
    public static function findById($id) {return parent::findById($id, self::CLASS_NAME);}
}
?>